//
//  UIImage+YFImage.m
//  Walker
//
//  Created by 代佳宏 on 2017/8/2.
//  Copyright © 2017年 齿轮易创. All rights reserved.
//

#import "UIImage+YFImage.h"

@implementation UIImage (YFImage)

+ (UIImage *)captureScreenWithView:(UIView *)view withRect:(CGRect)rect {
    if (view == nil) {
        view = [[UIApplication sharedApplication] keyWindow];
        rect = view.bounds;
    }
    UIGraphicsBeginImageContextWithOptions(rect.size, view.opaque, 0);
    [view drawViewHierarchyInRect:rect afterScreenUpdates:YES];
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}

+ (UIImage *)captureScreenWithView:(UIView *)view {
    return [self captureScreenWithView:view withRect:view.bounds];
}

+ (UIImage *)captureScreen {
    return [self captureScreenWithView:nil withRect:CGRectNull];
}
@end
